Hey there. 1
I've got a simple practice activity here that I'd like for you to attempt to solve regarding if statements. 2
You're going to create a variable here and you're going to call it weather and set it to a string like 3
overcast. 4
Using this variable, I'd like for you to create an if statement to check if the variable is equivalent 5
to another string. 6
So if it's snowing out, then print into the console. 7
Today is a cold day. 8
If it's rainy out, then print. 9
Grab an umbrella, it's raining. 10
If it's overcast, then print. 11
Today is cloudy. 12
Otherwise, if none of those evaluated are true, then you can print. 13
It's a nice sunny day. 14
So please pause the video and take a minute or two to solve and finish this activity. 15
I'll show you my solution in a little bit. 16
Okay, So to solve this problem, I'm going to create a variable here. 17
Call it weather. 18
And I'll set the string to be overcast. 19
Next, I'll create a new if statement and pass my weather variable. 20
And then using the operator we saw earlier to compare equivalence, 21
I'll check to see if the string is equal to snowing. 22
If so, we'll print. 23
Today is a cold day. 24
Else if the weather is equivalent to raining. 25
Then we'll print. 26
Grab an umbrella. 27
It's raining. 28
Else if the weather is overcast. 29
Then we'll print. 30
Today is cloudy. 31
And lastly, we'll use else here. 32
And just print. 33
It's a nice sunny day. 34
When all the other conditions did not evaluate to true. 35
Now we can run our game and see if the results we get are the ones we expect. 36
Great. 37
Now we can end the test and continue changing this variable to check the other parts of our if statement. 38
So I'll just change the value here to be snowing and then we can test to see if we get. 39
Today is a cool day and we do. 40
Let me end the test and then I'll change it to. 41
Partly cloudy and see if we get the message. 42
It's a nice sunny day and we do. 43
Excellent.